<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>修改密码</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta http-equiv="Cache-Control" content="no-transform">
		<meta name="format-detection" content="telephone=no">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<link rel="stylesheet" href="style/css/basic.css">
		<link rel="stylesheet" href="style/plugin/layui/css/layui.css" />
		<link rel="stylesheet" href="style/css/new_phone.css" />
		<script type="text/javascript" src="style/plugin/mui/js/mui.min.js"></script>
		<script type="text/javascript" src="style/js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="style/plugin/layui/layui.js"></script>
		<script type="text/javascript" src="style/mockjs/dist/mock.js"></script>
		<script type="text/javascript" src="style/js/basic.js"></script>

	</head>

	<body>
		<div id="header">
			<h1>修改密码</h1>
			<span class="backicon"></span>
		</div>
		<div class="body">
			<div class="bg">
				<form>
					<div class="txt">检测到当前账号为<em id="tel"></em></div>

					<div class="tel">
						<label>验证码</label>
						<input type="number" placeholder="验证码" name="tel" class="sms_code" />
						<i class="clear_input clear_code"></i>
						<button class="get_code" id="getting">获取验证码</button>
					</div>
					<div class="tel">
						<label>新密码</label>
						<input type="password" placeholder="请输入新密码" name="psw" class="phonenum" />
						<i class="clear_input"></i>
					</div>
				</form>
				<div class="button pwdbtn">
					<a href="javscript:void(0);">保存新密码</a>
				</div>
			</div>
		</div>
		<script>
			mui.plusReady(function(){
				var ticket=localStorage.getItem("tick")
                var sign=localStorage.getItem("sig")
				$("input").each(function() {
					var vdefault = this.value;
					$(this).focus(function() {
						$(this).next().css("opacity", "1")
					});
					$(".clear_input").click(function() {
						$(this).prev().val("")
					})
					$(this).blur(function() {
			
						$(this).next().css("opacity", "0")
					})
			
				});
			
				//	获取验证码
			
				var countdown = 60;
			
				function sendemail() {
					var obj = $("#getting");
					settime(obj);
			
				}
			
				function settime(obj) { //发送验证码倒计时
					mui.ajax(domain+"/sms/changePwd?t="+ticket+"&sign="+sign,{//获取验证码
				    	dataType:"json",
				    	type:"post",
				    	data:{
				    		phone:$("#tel").text()
				    	},
				    	timeout:10000,
				    	//headers:{'Content-Type':'application/json'},
				    	success:function(data){	  
				    		if(data.code==1){
				    			mui.toast("发送成功")	
				    			countdown=60
				    			obj.attr('disabled', true);
				    			var timer=setInterval(function(){
				    			    obj.html("重新发送(" + countdown + ")");
								    countdown--;
								    if(countdown==0){
										clearInterval(timer)
										obj.attr('disabled', false);
										//obj.removeattr("disabled"); 
										obj.html("获取验证码");
										countdown = 60;
									}
				    			},1000)
				    			//console.log(countdown)
								
				    		}else if(data.code==0){
				    			mui.toast("发送失败",{duration:"short"})
				    		}
				    	},
				    	error:function(xhr,type,errorThrown){
				    		alert(type)
				    	}
				    })
				}
					$(".pwdbtn").click(function(){
						var roletype=sessionStorage.getItem("rol")
						if($('.phonenum').val()==''){
							mui.toast("请输入新密码")
						}else if($(".sms_code").val()==''){
							mui.toast("请输入验证码")
						}else{
						    mui.ajax(domain+"/member/getInfo?t="+ticket+"&sign="+sign,{//获取用户信息
						    	dataType:"json",
						    	type:"post",
						    	timeout:10000,
						    	//headers:{'Content-Type':'application/json'},
						    	success:function(data){	 
						    		if(data.code==1){
							    		mui.ajax(domain+"/member/changePwd?t="+ticket+"&sign="+sign,{//修改密码
									    	dataType:"json",
									    	type:"post",
									    	data:{
									    		phone:data.data.phone,
									    		code:$(".sms_code").val(), 
									    		password:$(".phonenum").val()
									    	},
									    	timeout:10000,
									    	//headers:{'Content-Type':'application/json'},
									    	success:function(res){	  
									    		if(res.code==1){
	                                                mui.toast("修改成功")
	                                                if(roletype==1){
	                                                	openurl("agent_index")
	                                                }else if(roletype==2){
	                                                	openurl("sales_index")
	                                                }else if(roletype==4){
	                                                	openurl("recommend_index")
	                                                }else{
	                                                	console.log("页面不存在")
	                                                }
									    		}else{
									    			mui.toast(res.msg,{duration:"short"})
									    		}
									    	},
									    	error:function(xhr,type,errorThrown){
									    		alert(type)
									    	}
									    })	
		
						    		}else if(data.code==0){
						    			mui.toast("发送失败",{duration:"short"})
						    		}
						    	},
						    	error:function(xhr,type,errorThrown){
						    		alert(type)
						    	}
						    })	
						}
						
					})
					
				
				$("#getting").click(function(e) {
					e.preventDefault()
					sendemail()
				})
			
				//	禁止input光标
				$('input[readonly]').on('focus', function() {
					$(this).trigger('blur');
				});
			    mui.ajax(domain+"/member/getInfo?t="+ticket+"&sign="+sign,{//获取用户信息
			    	dataType:"json",
			    	type:"post",
			    	timeout:10000,
			    	//headers:{'Content-Type':'application/json'},
			    	success:function(data){	 
			    		console.log(data)
			    		if(data.code==1){
			    			sessionStorage.setItem("rol",data.data.role)
				    		$("#tel").html(data.data.phone)
	
			    		}else if(data.code==0){
			    			mui.toast("数据请求失败！",{duration:"short"})
			    		}
			    	},
			    	error:function(xhr,type,errorThrown){
			    		alert(type)
			    	}
			    })
			})
			
		</script>
	</body>
    
</html>